package my.db.DAO;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import my.db.DTO.ArticleTypeDTO;
import config.EstablishConnection;

public class ArticleTypeDAO {
	private EstablishConnection econ=null;
	private PreparedStatement pstmt=null;
	private ResultSet rs=null;
	/*
	 * Constructor Initialized
	 */
	public ArticleTypeDAO(){
		econ=EstablishConnection.CreateInstance();
	}
	/*
	 * Getting info of article type 
	 *  if true 
	 *  	return object ArticleTypeDTO
	 *  else 
	 *  	return null
	 */
	public ArrayList<ArticleTypeDTO> getListArticleType(){
		ArrayList<ArticleTypeDTO> lst_at=new ArrayList<>();
		ArticleTypeDTO atdto=null;
		String sql="select * from ArticleType";
		try{
			pstmt=econ.conection.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()){
				atdto=new ArticleTypeDTO();
				atdto.setTypeID(rs.getInt(1));
				atdto.setTypeName(rs.getString(2));
				lst_at.add(atdto);
				atdto=null;
			}
		}catch(SQLException e){
			System.out.println("error article type");
			return null;
		}
		return lst_at;
	}
}
